package transformations;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


public class XmlHtmlTransformation {
    
    public XmlHtmlTransformation(){
        
    }
    
    public void transform(){
        Processor proc = new Processor(false);
            XsltCompiler comp = proc.newXsltCompiler();
            XsltExecutable exp=null;
        try {
            exp = comp.compile(new StreamSource(new File("src/java/xmlProcesses/XMLTransformation1.xsl")));
        
            XdmNode source=proc.newDocumentBuilder().build(new StreamSource(new File("src/java/xmlProcesses/resultat.xml")));
        
            Serializer out = new Serializer();
            out.setOutputProperty(Serializer.Property.METHOD, "html");
            out.setOutputProperty(Serializer.Property.INDENT, "yes");
            out.setOutputFile(new File("results.html"));
            XsltTransformer trans = exp.load();
            trans.setInitialContextNode(source);
            trans.setDestination(out);
        
            trans.transform();
    }catch (SaxonApiException ex) {
            Logger.getLogger(XmlHtmlTransformation.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    public static void main(String [] a){
            XmlHtmlTransformation x=new XmlHtmlTransformation();
            x.transform();
                    
        }
}
